<!DOCTYPE html>
<html lang="en">
<head>
<title>黑名单管理</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<script src="../../layui/layui.js"></script>
<script src="../../js/jquery-1.8.3.js"></script>
<script src="../../js/util.js"></script>
<script type="text/javascript">

	layui.use([ 'layer', 'table', 'form', 'jquery', 'element' ], function() {
		var table = layui.table;
		var layer = layui.layer;
		var form = layui.form;
		var $ = layui.$;
		var user;
		var option = {
			elem : "#table", //表格id
			id : "modelReload", //id
			url : '/blackUser/find',
			method : 'post',
			request : {
				pageName : 'page',
				limitName : 'limit'
			},
			response : {
				statusName : 'code',
				statusCode : 0,
				msgName : 'msg',
				countName : 'count',
				dataName : 'data'
			},
			page : true,
			count : "count",
			limit : 10,
			limits : [ 10, 20, 30, 40, 50 ],
			layout : [ 'prev', 'page', 'next' ],
			prev : "上一页",
			next : "下一页",
			cols : [ [ //表头
				{
					field : 'blackLevel',
					title : '级别',
					templet : function(d) {
						if (d.blackLevel == '1') {
							return '省级';
						} else if (d.blackLevel == '2') {
							return '地市级';
						} else if (d.blackLevel == '3') {
							return '区县级';
						} else if (d.blackLevel == '4') {
							return '项目级';
						}
					}
				},
				{
					field : 'numberType',
					title : '类型',
					templet : function(d) {
						if (d.numberType == '1') {
							return '号码';
						} else if (d.numberType == '2') {
							return '号段';
						}
					}
				},
				{
					field : 'belong',
					title : '省份/地市/区县/项目'
				},
				{
					field : 'decodePhoneNumber',
					title : '投诉手机号/号段'
				},
				{
					field : 'enterTime',
					title : '投诉时间'
				},
				{
					field : 'operation',
					title : '操作',
					toolbar : '#barDemo'
				}
			] ]
		};
		table.render(option);

		$('#query').on('click', function() {
			var index = layer.load(1, {
				shade : [ 0.1, '#fff' ] //0.1透明度的白色背景
			});
			var phoneNumber;
			var numberType = $("input[name='numberType']:checked").val();
			if(numberType==1){
				phoneNumber = $("#phoneNumber").val();
			}else if(numberType==2){
				phoneNumber = $("#phoneNumber2").val();
			}

			console.info("-----"+phoneNumber);
			var cityId = $("#cityId").val();
			var countyId = $("#countyId").val();
			var blackLevel = $("input[name='blackLevel']:checked").val();

			var mgrId = $("#mgrId").val();
			var mgrName = $("#mgrName").val();
			table.reload('modelReload', {
				method : 'post',
				page : {
					curr : 1
				},
				where : {
					phoneNumber : phoneNumber,
					numberType : numberType,
					cityId : cityId,
					countyId : countyId,
					mgrId : mgrId,
					blackLevel : blackLevel,
					mgrName : mgrName,
					duty : user.duty
				}
			});
			layer.close(index);
		});


		table.on('tool(table)', function(obj) {
			var data = obj.data;
			layer.confirm('您确定要删除吗？', {
				icon : 3,
				title : '提示'
			}, function(index) {
				var url = "/blackUser/delete";
				var param = {
					phoneNumber : data.phoneNumber,
					mgrId : data.mgrId,
					cityId : data.cityId,
					countyId : data.countyId,
					blackLevel : data.blackLevel
				};
				$.ajax({
					type : 'post',
					data : param,
					url : url,
					beforeSend : function() {},
					success : function(json) {

						if (json.code == 0) {
							layer.confirm('删除成功', {
								btn : [ '确认' ] //按钮
							}, function() {
								location.href = "blackManage.html";
							});
						} else {
							layer.msg(json.data.msg);
						}
					},
					complete : function() {}
				});
			});
		});



		$('#insert').on('click', function() {
			window.location.href = 'blackAdd.html';
		});

		//监听区县
		form.on('select(cityId)', function(data) {
			var data2 = selectCountyId(data.value);
			appendCounty(data2);
			var data = selectMgrInfo(data.value);
			appendMgr(data);
		});

		//监听项目
		form.on('select(countyId)', function(data) {
			var data1;
			if (null != data.value && "" != data.value) {
				data1 = selectMgrInfo(data.value);
			} else {
				var cityId = $("#cityId").val();
				data1 = selectMgrInfo(cityId);
			}
			appendMgr(data1);
		});

		//动态拼接区县
		function appendCounty(data) {
			if (data.length != null) {
				var options = '<option value="">请先选择地市</option>';
				for (var i = 0; i < data.length; i++) {
					options += '<option value="' + data[i].countyId + '">' + data[i].countyName + '</option>';
				}
				$('#countyId').html(options);
			} else {
				$('#countyId').html('该地市下没有区县');
			}
			form.render();
		}

		//动态拼接项目
		function appendMgr(data) {
			if (data.length != null) {
				var options = '<option value="">请选择</option>';
				for (var i = 0; i < data.length; i++) {
					options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
				}
				$('#mgrId').html(options);
			} else {
				$('#mgrId').html('<option value="">该区县下没有项目</option>');
			}
			form.render();
		}

		//根据城市ID查询区县
		function selectCountyId(cityId) {
			var data;
			var url = '/util/findCountyByCityId?cityId=' + cityId;
			$.ajax({
				type : 'post',
				async : false,
				url : url,
				success : function(json) {
					data = json.data;
				},
				error : function() {
					layer.msg('系统异常，请联系管理员处理!');
				}
			}
			);
			return data;
		}

		//根据城市ID和区县查询项目
		function selectMgrInfo(countyId, mgrName) {
			var data;
			var url = '/util/findByMgrId?countyId=' + countyId;
			$.ajax({
				type : 'post',
				async : false,
				url : url,
				success : function(json) {
					data = json.data;
				},
				error : function() {
					layer.msg('系统异常，请联系管理员处理!');
				}
			}
			);
			return data;
		}
		$("#test3").click(function() {
			var params = {
				taskId : "123",
				checkResult : "1",
				checkMsg : "33333"
			}
			var jsonParams = JSON.stringify(params);
			$.ajax({
				contentType : "application/json;charset=UTF-8",
				type : 'post',
				async : false,
				data : jsonParams,
				url : '/smsInterfaceJzzw/checkResultSyn',
				success : function(json) {
					alert(json);
				}
			});
		});
		$("#test2").click(function() {
			//var req = "{\"ops\":\"1\",\"sendNumber\":\"10657016120003\",\"taskId\":\"100007\",\"taskName\":\"街道宣传任务test7\",\"sendContent\":\"xxxxxxxxxxxxxxxxx\",\"taskStatus\":\"1\",\"taskStart\":\"2019-08-29 00:08:00\",\"taskEnd\":\"2019-08-29 00:20:00\",\"streamSeq\":\"20190809110306100001\"}";
			var req = "{\"ops\":\"2\",\"sendNumber\":\"10657016120003\",\"taskId\":\"100007\",\"taskName\":\"街道宣传任务test777\",\"taskStatus\":\"1\",\"taskStart\":\"2019-08-29 00:08:00\",\"taskEnd\":\"2019-08-29 00:20:00\",\"streamSeq\":\"20190809110306100001\"}";
			$.ajax({
				type : 'post',
				async : false,
				data : "taskSynReq=" + req,
				url : '/smsInterfaceJzzw/taskSyn',
				success : function(json) {
					var jsonParams = JSON.stringify(json);
					alert(jsonParams);
				}
			});
		});
		$("#test").click(function() {
			var req = "{\"mgrName\":\"街道办欢迎短信项目3\",\"sendNumber\":\"10657016110001\",\"cityId\":\"11\",\"streamSeq\":\"20190829110304100001\"}";
			$.ajax({
				type : 'post',
				async : false,
				data : "sendNumberSynReq=" + req,
				url : '/smsInterfaceJzzw/sendNumberSyn',
				success : function(json) {
					alert("success");
				}
			});
		});

		//身份识别
		$(document).ready(function() {
			$(".cityId").css("display", "none");
			$(".countyId").css("display", "none");
			$(".mgrId").css("display", "none");
			$(".mgrName").css("display", "none");
			$.ajax({
				type : 'post',
				async : false,
				url : '/util/findUser',
				success : function(json) {
					user = json;
					if (json.duty == 1) { //地市
						$(".cityId").css("display", "none");
						$("#cityId").val(json.cityId);
						$("#cityId").attr("disabled", true);
						var data2 = selectCountyId(json.cityId);
						appendCounty(data2);
						var data1 = selectMgrInfo(json.cityId);
						appendMgr(data1);
						form.render();
					} else if (json.duty == 2) { //项目
						appendMgr(json.list);
						var data2 = selectCountyId(json.cityId);
						appendCounty(data2);
						$("#cityId").val(json.cityId);
						$("#cityId").attr("disabled", true);
						$("#countyId").val(json.countyId);
						$("#countyId").attr("disabled", true);
						form.render();
					} else if (json.duty == 3) { //区县
						$("#cityId").val(json.cityId);
						$("#cityId").attr("disabled", true);
						var data = selectMgrInfo(json.countyId);
						appendMgr(data);
						var data2 = selectCountyId(json.cityId);
						appendCounty(data2);
						$("#countyId").val(json.countyId);
						$("#countyId").attr("disabled", true);
						form.render();
					} else if (json.duty == 4) {
						if (json.cityId == 25) { //省权限

						} else if (json.cityId != 25 && checkStr(json.countyId) == "") { //地市权限
							$("#cityId").val(json.cityId);
							$("#cityId").attr("disabled", true);
							var data2 = selectCountyId(json.cityId);
							appendCounty(data2);
							var data1 = selectMgrInfo(json.cityId);
							appendMgr(data1);
							form.render();
						} else if (json.cityId != 25 && checkStr(json.countyId) != "") { //区县权限
							$("#cityId").val(json.cityId);
							$("#cityId").attr("disabled", true);
							var data = selectMgrInfo(json.countyId);
							appendMgr(data);
							var data2 = selectCountyId(json.cityId);
							appendCounty(data2);
							$("#countyId").val(json.countyId);
							$("#countyId").attr("disabled", true);
							form.render();
						}
					}
				},
				error : function() {
					layer.msg('系统异常，请联系管理员处理!');
				}
			});

			$("#numberType").click(function() {
				console.info("-----");
				var numberType = $("input[name='numberType']:checked").val();
				if(numberType == "1"){
					$(".phoneNumber").css("display", "");
					$(".phoneNumber2").css("display", "none");

				}else if(numberType == "2"){
					$(".phoneNumber2").css("display", "");
					$(".phoneNumber").css("display", "none");
				}
			})

			$(".blackLevel").click(function() {
				var blackLevel = $("input[name='blackLevel']:checked").val();
				if (blackLevel == "0" || blackLevel == "1") {
					$(".cityId").css("display", "none");
					$(".countyId").css("display", "none");
					$(".mgrId").css("display", "none");
					$(".mgrName").css("display", "none");
					if (user.duty == 1) {
						$("#cityId").val(user.cityId);
					} else {
						$("#cityId").val("");
					}
					$("#countyId").val("");
					$("#mgrId").val("");
					$("#mgrName").val("");
					var select = "dd[lay-value='']";
					$('#cityId').siblings("div.layui-form-select").find('dl').find(select).click();
					$('#countyId').siblings("div.layui-form-select").find('dl').find(select).click();
					$('#mgrId').siblings("div.layui-form-select").find('dl').find(select).click();
				} else if (blackLevel == "2") {
					$(".cityId").css("display", "");
					$(".countyId").css("display", "none");
					$(".mgrId").css("display", "none");
					$(".mgrName").css("display", "none");
					$("#countyId").val("");
					$("#mgrId").val("");
					$("#mgrName").val("");
					var select = "dd[lay-value='']";
					$('#countyId').siblings("div.layui-form-select").find('dl').find(select).click();
					$('#mgrId').siblings("div.layui-form-select").find('dl').find(select).click();
				} else if (blackLevel == "3") {
					$(".cityId").css("display", "");
					$(".countyId").css("display", "");
					$(".mgrId").css("display", "none");
					$(".mgrName").css("display", "none");
					$("#mgrId").val("");
					$("#mgrName").val("");
					var select = "dd[lay-value='']";
					$('#mgrId').siblings("div.layui-form-select").find('dl').find(select).click();
				} else if (blackLevel == "4") {
					$(".cityId").css("display", "");
					$(".countyId").css("display", "");
					$(".mgrId").css("display", "");
					$(".mgrName").css("display", "");
				}

				var index = layer.load(1, {
					shade : [ 0.1, '#fff' ] //0.1透明度的白色背景
				});
				var phoneNumber = $("#phoneNumber").val();
				var cityId = $("#cityId").val();
				var countyId = "";
				var blackLevel = $("input[name='blackLevel']:checked").val();
				var mgrId = "";
				var mgrName = "";
				table.reload('modelReload', {
					method : 'post',
					page : {
						curr : 1
					},
					where : {
						phoneNumber : phoneNumber,
						cityId : cityId,
						countyId : countyId,
						mgrId : mgrId,
						blackLevel : blackLevel,
						mgrName : mgrName,
						duty : null
					}
				});
				layer.close(index);
			});

		});

	});
</script>
<script type="text/html" id="barDemo">
        <a href="#" lay-event="delete">删除</a>&nbsp;
    </script>
</head>
<body>
	<div class="layui-content-body">
		<div class="scroll-box">
			<div class="breadcrumb-box">
				<span class="layui-breadcrumb" lay-separator="|"> <a
					href="javascript:returnIndex2()">首页&nbsp;</a> <a href="">黑名单管理</a>
					<a href=""> 黑名单管理</a>
				</span>
			</div>
			<div class="content-box">
				<div class="form-select-box">
					<div class="layui-form layui-form-pane" id="form">
						<div class="layui-form-item blackLevel">
							<label class="layui-form-label" style="width:120px">黑名单级别</label>
							<div class="layui-input-block">
								<input class="radioItem" lay-filter="gis" type="radio"
									name="blackLevel" title="全部" onclick="ChooseRadio(this)"
									value="0" checked="checked"> <input class="radioItem"
									lay-filter="gis" type="radio" name="blackLevel" title="省级"
									onclick="ChooseRadio(this)" value="1"> <input
									class="radioItem" lay-filter="gis" type="radio"
									name="blackLevel" title="地市级" onclick="ChooseRadio(this)"
									value="2"> <input class="radioItem" lay-filter="gis"
									type="radio" name="blackLevel" title="区县级"
									onclick="ChooseRadio(this)" value="3"> <input
									class="radioItem" lay-filter="gis" type="radio"
									name="blackLevel" title="项目级" onclick="ChooseRadio(this)"
									value="4">
							</div>
						</div>


						<div class="layui-form-item">
							<div class="layui-inline cityId">
								<label class="layui-form-label">地市</label>
								<div class="layui-input-block" style="width:120px;">
									<select name="cityId" lay-filter="cityId" id="cityId">
										<option value="">全部</option>
										<option value="11">苏州</option>
										<option value="12">淮安</option>
										<option value="13">宿迁</option>
										<option value="14">南京</option>
										<option value="15">连云港</option>
										<option value="16">徐州</option>
										<option value="17">常州</option>
										<option value="18">镇江</option>
										<option value="19">无锡</option>
										<option value="20">南通</option>
										<option value="21">泰州</option>
										<option value="22">盐城</option>
										<option value="23">扬州</option>
										<option value="25">省级</option>
									</select>
								</div>
							</div>
							<div class="layui-inline countyId">
								<label class="layui-form-label">区县</label>
								<div class="layui-input-block" style="width:150px">
									<select name="countyId" lay-filter="countyId" id="countyId">
										<option value="">全部</option>
									</select>
								</div>
							</div>
							<div class="layui-inline mgrId">
								<label class="layui-form-label">项目名称</label>
								<div class="layui-input-block" style="width:150px">
									<select name="mgrId" lay-filter="mgrId" id="mgrId">
										<option value="">请选择</option>
									</select>
								</div>
							</div>
							<div class="layui-inline mgrName">
								<label class="layui-form-label">项目简称</label>
								<div class="layui-input-block" style="width:150px">
									<input type="text" name="mgrName" id="mgrName"
										lay-verify="required" placeholder="请输入" autocomplete="off"
										class="layui-input" />
								</div>
							</div>
						</div>

						<div class="layui-form-item" id = "numberType">
							<label class="layui-form-label" style="width:120px">投诉类型</label>
							<div class="layui-input-block">
								<input class="radioItem" lay-filter="gis" type="radio"
									   name="numberType" title="号码" onclick="ChooseRadio(this)"
									   value="1" checked="checked">
								<input class="radioItem" lay-filter="gis" type="radio" name="numberType" title="号段"
									   onclick="ChooseRadio(this)" value="2">
							</div>
						</div>
						<div class="layui-form-item phoneNumber">
							<label class="layui-form-label">投诉号码</label>
							<div class="layui-input-block">
								<input type="text" name="date" id="phoneNumber"
									autocomplete="off" class="layui-input" placeholder="请输入"
									lay-verify="required" style="width:180px">
							</div>
						</div>
						<div class="layui-form-item phoneNumber2" style="display:none;">
							<label class="layui-form-label">投诉号段</label>
							<div class="layui-input-block">
								<input type="text" name="date" id="phoneNumber2"
									   autocomplete="off" class="layui-input" placeholder="请输入"
									   lay-verify="required" style="width:180px">
							</div>
						</div>
						<div class="layui-block">
							<button class="layui-btn layui-btn-normal" id="query">查&nbsp;询</button>
							<button class="layui-btn layui-btn-normal" id="insert"
								type="button">
								<i class="layui-icon">&#xe608;</i> 添加
							</button>
						</div>
					</div>
				</div>
				<!--表格-->
				<div class="layui-table">
					<table id="table" lay-filter="table"></table>
				</div>
			</div>
		</div>
	</div>
	</div>
</body>
</html>